! *message* module
!
! Purpose:
!   provide unified message displaying way
!
! Author:
!   Name: DONG Li
!   Email: dongli@lasg.iap.ac.cn

module message

    implicit none

    private

    public message_show

    integer, parameter, public :: ERROR_MSG = 1
    integer, parameter, public :: NOTICE_MSG = 2

contains

    subroutine message_start(msg_type)
        integer, intent(in) :: msg_type

        character(10) :: value
        integer :: i, temp

        write(*, *)
        write(*, "('==================================================')")
        select case(msg_type)
        case(ERROR_MSG)
            write(*, "('                    ERROR   ')")
        case(NOTICE_MSG)
            write(*, "('                    NOTICE  ')")
        case default
            write(*, "('                   MESSAGE  ')")
        end select
        write(*, *)

        return
    end subroutine message_start

    subroutine message_show(msg_type, module_location, method_location, msg_content)
        integer, intent(in) :: msg_type
        character(*), intent(in) :: module_location, method_location, msg_content

        call message_start(msg_type)
        write(*, "('message source:')")
        write(*, "('  module: ', a)") module_location
        write(*, "('  method: ', a)") method_location
        write(*, "('message content:')")
        write(*, "('  ', a)") msg_content
        write(*, *)
        call message_end
    
    end subroutine message_show

    subroutine message_end
        integer :: i

        write(*, "('==================================================')")
        write(*, *)

        return
    end subroutine message_end

end module message
